package com.feicheng.iou.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnResource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

//@Configuration
//@Slf4j
public class SystemConfig implements WebMvcConfigurer {

    @Resource
    HandlerInterceptor loginAuthInterceptor;
//    @Resource
//    HandlerInterceptor corsInterceptor;
//	@Resource
//	PermissionInterceptor permissionInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(corsInterceptor).excludePathPatterns( //https://fq.kerchin.xyz/weixin/wxH5login
//                "/iou/system/login",
//                "/iou/**",
//                "https://fq.kerchin.xyz/weixin/wxH5login"
////                "/iou/system/student/login",
////                "/iou/system/student/loginout",
////                "/iou/system/student/password",
////                "/iou/system/student/info/{userId}",
////                "/iou/system/student/info/update",
////                "/iou/system/student/payment/{userId}"
//        );
        registry.addInterceptor(loginAuthInterceptor).excludePathPatterns(
                "/iou/system/login",
                "/iou/system/student/login",
                "/iou/system/student/loginout",
                "/iou/system/student/password",
                "/iou/system/student/info/{userId}",
                "/iou/system/student/info/update",
                "/iou/system/student/payment/{userId}");
        //loginObject.userList()
    }

//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
////        registry.addMapping("/**").allowedOrigins("*").allowedHeaders(CorsConfiguration.ALL)
////                .allowedMethods(CorsConfiguration.ALL).allowCredentials(true).maxAge(3600);
//                                               //weChatPay
//        registry.addMapping("/**").allowedOriginPatterns("*").allowedHeaders(CorsConfiguration.ALL)
//        .allowedMethods(CorsConfiguration.ALL).allowCredentials(true).maxAge(3600);
//
//
//    }


}
